// created by noellynch
// Aug 14, 2010

package com.sceneworker.monitorpopup.panels;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import com.jme.scene.Node;
import com.jme2utils.staticutils.ModelUtils;
import com.myjavautils.GenericUtils;
import com.myjavautils.swing.MigLayoutUtils;
import com.myjavautils.swing.SimpleAlert;
import com.myjavautils.swing.SwingComponentFactory;

public class FolderImportPanel extends JPanel {
	private		Object		mcl_main;
	private		File		mcl_dir;
	private		JLabel		mcl_dirLbl;
	
	public	FolderImportPanel(Object cl_main) {
		MigLayoutUtils.asMigLayout(this);
		
		mcl_main = cl_main;
		
		JButton		lcl_btn = SwingComponentFactory.makeAButton("Locate Folder", new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				mcl_dir = GenericUtils.getAFile(null, true, false);
				
				if(mcl_dir != null) {
					mcl_dirLbl.setText("dir = " + mcl_dir.getName());
				} else {
					mcl_dirLbl.setText("");
				}
			}
		});
		add(lcl_btn);
		
		mcl_dirLbl = SwingComponentFactory.makeALabel("");
		add(mcl_dirLbl, "wrap");
		
		JButton		lcl_import = SwingComponentFactory.makeAButton("Import", new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				if(mcl_dir == null) {
					SimpleAlert.doAlert("You have not selected a directory.", null);
					return;
				}
				
				if(mcl_main instanceof Node) {
					ModelUtils.loadFolder(mcl_dir, (Node)mcl_main);
				} else {
					SimpleAlert.doAlert("The object selected in the scene graph must be a node.", null);
				}
			}
		});
		MigLayoutUtils.makeRightAlignedButtonBar(this, lcl_import);
		
	}
}
